{extend name='table'}

{block name="button"}
<!--{if auth("remove")}-->
<a data-confirm="确定永久删除这些账号吗？" data-table-id="FileTable" data-action='{:url("remove")}' data-rule="id#{id}" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</a>
<!--{/if}-->
{/block}

{block name="content"}
<div class="think-box-shadow">
    {include file='file/index_search'}
    <table id="FileTable" data-url="{:sysuri('index')}" data-target-search="form.form-search"></table>
</div>
<script>
    $(function () {
        $('#FileTable').layTable({
            even: true, height: 'full',
            sort: {field: 'id', type: 'desc'},
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'id', title: 'ID', width: 80, align: 'center', sort: true},
                {field: 'name', title: '文件名称', width: '12%', align: 'center'},
                {field: 'hash', title: '文件哈希', width: '15%', align: 'center', templet: '<div><code>{{d.hash}}</code></div>'},
                {
                    field: 'size', title: '文件大小', align: 'center', width: '8%', sort: true, templet: function (d) {
                        return formatSize(d.size)
                    }
                },
                {field: 'xext', title: '文件后缀', align: 'center', width: '8%', sort: true},
                {
                    field: 'xurl', title: '查看文件', width: '8%', align: 'center', templet: function (d) {
                        if (typeof d.mime === 'string' && /^image\//.test(d.mime)) {
                            return laytpl('<div class="headimg headimg-no headimg-ss margin-0" data-tips-hover data-tips-image="{{d.xurl}}" style="background-image:url({{d.xurl}})"></div>').render(d)
                        } else {
                            return laytpl('<div><a target="_blank" href="{{d.xurl}}">查看</a></div>').render(d);
                        }
                    }
                },
                {
                    field: 'isfast', title: '上传方式', align: 'center', width: '8%', templet: function (d) {
                        return d.isfast ? '<b class="color-green">秒传</b>' : '<b class="color-blue">普通</b>';
                    }
                },
                {field: 'ctype', title: '存储方式', align: 'center', width: '10%'},
                {field: 'create_at', title: '上传时间', align: 'center', width: '15%', sort: true},
                {toolbar: '#toolbar', title: '操作面板', align: 'center', minWidth: 90, fixed: 'right'}
            ]]
        });
    });

    function formatSize(size, fixed, units) {
        var unit;
        units = units || ['B', 'K', 'M', 'G', 'TB'];
        while ((unit = units.shift()) && size > 1024) size = size / 1024;
        return (unit === 'B' ? size : size.toFixed(fixed === undefined ? 2 : fixed)) + unit;
    }
</script>

<script type="text/html" id="toolbar">
    <!--{if auth("remove")}-->
    <a class="layui-btn layui-btn-sm layui-btn-danger" data-action="{:url('remove')}" data-value="id#{{d.id}}">删 除</a>
    <!--{/if}-->
</script>
{/block}
